#pragma once

#include "CircuitQueue.h"
class  SendBuffer
{
public:
	 SendBuffer()
	 {
		 m_pQueue = NULL;
		 m_bComplete = true;
	 }
	~ SendBuffer()
	{
		if (m_pQueue)
		{
			delete m_pQueue;
			m_pQueue = NULL;
		}
	}

	void Create(size_t nBufferSize, size_t nExtraSize)
	{
		m_pQueue = new CircuitQueue<unsigned char>();
		m_pQueue->Create(nBufferSize, nExtraSize);
		m_bComplete = true;
	}

	void Completion(size_t nBytesSend)
	{
		m_pQueue->Dequeue(NULL, nBytesSend);
		m_bComplete = true;
	}

	bool GetSendParam(unsigned char** ppSendPtr, size_t& nLen)
	{
		if (IsReadyToSend() == false)
		{
			nLen = 0;
			return false;
		}

		*ppSendPtr = m_pQueue->GetReadPtr(nLen);
		m_bComplete = false;
		return true;
	}

	bool Write(unsigned char* pPacket, size_t nLen)
	{
		return m_pQueue->Enqueue(pPacket, nLen);
	}

	bool IsReadyToSend()
	{
		return m_bComplete && (m_pQueue->GetLength() > 0);
	}

private:
	CircuitQueue<unsigned char>* m_pQueue;
	bool m_bComplete;
};
